package Classes.GameDatas
{
	import Classes.GameUtils.MyTipSprite;
	import Classes.GameUtils.ToolTip_Sprite;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MMT_Character;
	import Classes.Interfaces.I_TimeUnit;
	import Classes.Managers.M_BaseCartoons;
	import Classes.Managers.M_Timer;
	import Classes.staticinfo.Language;

	/**
	 * 被雇佣好友信息处理GD类 
	 * @author Administrator
	 */	
	public class GD_HiredFriend extends GD_Player implements I_TimeUnit
	{
		private var _playerID:Number; /*玩家ID*/
		
		private var _playerName:String; /*玩家名字*/
		private var _playerViewID:String; /*玩家头像ID*/
		private var _playerJob:int; /*玩家职业*/
		private var _playerSex:String; /*玩家性别*/
		private var _playerLv:int; /*玩家等级*/
		private var _actPoint:int; /*行动点数*/
		
		private var _attRange:Number;/*人物攻击的范围*/
		private var _attactType:String;/*人物攻击方式*/
		private var _pf:String;//雇佣好友所在的平台
		
		/**
		 * 提示文本 
		 */		
		private var tips:String;
		
		private var _startHiredTime:Number;/*雇佣起始时间*/
		private var _weaponId:Number;/*武器ID*/
		
		private var _lastTimer:String="";/*玩家被雇佣的剩余时间*/
		
		private var _character:GD_Character; 
		
		private var _timeIsOver:Boolean;
		private var _isAddTimer:Boolean;
		public function GD_HiredFriend(isAddTimer:Boolean)
		{
			super();
			this._isAddTimer=isAddTimer;
			if(isAddTimer)
			{
				M_Timer.instance.joinUnit(this);
			}
		}
		
		private var callBackCreateFireFriend:Function;
		public function needCartoon(callFun:Function):void
		{
			this.callBackCreateFireFriend=callFun;
			M_BaseCartoons.instance.needLoadBaseCartoon(this.jobCartoonType, baseCartoonLoadOver);
		}
		
		private function baseCartoonLoadOver(cartoonType:String):void
		{
			this.character.view.setBaseCartoonsType(cartoonType);
			GV_Map.instance.creatCharacter(this.character, false);
			this.character.currentOwnWeapon=this.weaponId.toString();
			if(this._isAddTimer)
			{
				tips=Language.hirefriendInfo.replace("@fireName",this.playerName);
				tips=tips.replace("@weaponName",GD_Weapon.getWeaponInfoById(this.weaponId).zt_weapon_name);
				recordTimer();
				ToolTip_Sprite.getInstance().setTip(this.character.view,new MyTipSprite(tips+"<font color='#FFFFFF'>"+lastTimer+"</font>"),ToolTip_Sprite.DIRECTION_LEFT,true,40);
			}
			if(null!=callBackCreateFireFriend)
			{
				this.callBackCreateFireFriend(this.playerID);
			}
		}
		
		public function timeUpdate():void
		{
			//动态改变文本
			if(this.character.view.parent)
			{
				recordTimer();
				ToolTip_Sprite.getInstance().setTipTxt(tips+"<font color='#FFFFFF'>"+lastTimer+"</font>",this.character.view);
			}
			//以后冒泡用的  思路 当时间  距离结束时间   还有几秒时  就冒泡
			
			//当结束时间到达  就把角色从地图上面移除
			if(M_Timer.instance.nowTime-this.startHiredTime>=86400 && this.character.view.parent)//86400
			{
				this.isUpdateTime=false;
//				ToolTip_Sprite.getInstance().removeTip(this.character.view);
				//从地图上面移除此角色
				if((GV_Map.instance.controlTarget as MMT_Character).characterData.characterId==this.character.characterId)
				{
					GV_Map.instance.controlTarget	=	GD_Player.instance.character.view;
					GD_Player.instance.character.view.controlJianTouVisable(true);
				}
			
				ToolTip_Sprite.getInstance().removeTip(this.character.view);
				GV_Map.instance.removeCharacter(this.character);
				
				//把他的状态变为可以雇佣的
				GD_AllFriends.instance.getFriendInfoById(this._playerID).isHired=0;
				//从好友管理者那里将角色数据删除
				delete GD_AllFriends.instance.allHiredFriends[this._playerID];
			}
		}
		
		private function recordTimer():void
		{
			var timer:Number=86400-(M_Timer.instance.nowTime-this.startHiredTime);
			var hour:int=timer/3600;
			var min:int=(timer%3600)/60;
			var ms:int=timer%3600%60;
			this.lastTimer=hour+":"+min+":"+ms;
		}
		
		public function get isUpdateTime():Boolean
		{
			return _timeIsOver;
		}
		public function set isUpdateTime(value:Boolean):void
		{
			this._timeIsOver=value;
		}
		
		/**
		 * 玩家的男或者女的模型
		 * @return
		 */
		override public function get jobCartoonType():String
		{
			var paperType:String="character_girl1";
			if (this.playerSex == "1")
			{
				paperType="character_boy1";
			}
			return paperType;
		}
		
		/**
		 * 好友ID 
		 * @return 
		 */		
	 override public function get playerID():Number
		{
			return _playerID;
		}

		public function set playerID(value:Number):void
		{
			_playerID = value;
		}

		/**
		 * 好友名字
		 * @return 
		 */	
		override public function get playerName():String
		{
			return _playerName;
		}

		override public function set playerName(value:String):void
		{
			_playerName = value;
		}

		/**
		 * 好友头像地址 
		 * @return 
		 */	
		override public function get playerViewID():String
		{
			return _playerViewID;
		}

		override public function set playerViewID(value:String):void
		{
			_playerViewID = value;
		}

		/**
		 * 好友职业（擅长的领域） 
		 * @return 
		 */		
		override public function get playerJob():int
		{
			return _playerJob;
		}

		override public function set playerJob(value:int):void
		{
			_playerJob = value;
		}

		/**
		 * 好友性别 
		 * @return 
		 */	
		override public function get playerSex():String
		{
			return _playerSex;
		}

		override public function set playerSex(value:String):void
		{
			
			if(value=="2")
			{
				_playerSex = "0";
			}else{
				_playerSex = value;
			}
			
		}

		/**
		 * 好友等级 
		 * @return 
		 */	
		override public function get playerLv():int
		{
			return _playerLv;
		}

		override public function set playerLv(value:int):void
		{
			_playerLv = value;
		}

		public function get startHiredTime():Number
		{
			return _startHiredTime;
		}

		public function set startHiredTime(value:Number):void
		{
			_startHiredTime = value;
		}

		public function get weaponId():Number
		{
			return _weaponId;
		}

		public function set weaponId(value:Number):void
		{
			//改变射程跟攻击方式
			var obj:Object=GD_Weapon.getWeaponInfoById(value);
			this._attRange=Number(obj.zt_weapon_range);
			switch(Number(obj.zt_weapon_attack))
			{
				case 1:
					this._attactType="attack";
					break;
				case 2:
					this._attactType="attack_throw";
					break;
				case 3:
					this._attactType="attack_short";
					break;
			}
			_weaponId = value;
		}
		
		/**
		 *  人物攻击的范围  根据武器来
		 */
		override public function get attRange():Number
		{
			return _attRange;
		}
		
		/**
		 *人物攻击方式 
		 */
		override public function get attactType():String
		{
			return _attactType;
		}

		override public function get character():GD_Character
		{
			return _character;
		}

		public function set character(value:GD_Character):void
		{
			_character = value;
		}
		

		override public function get actPoint():int
		{
			return _actPoint;
		}

		override public function set actPoint(value:int):void
		{
			_actPoint = value;
			this.character.actPoint=value;
		}

		/**
		 *玩家被雇佣的剩余时间 
		 */
		public function get lastTimer():String
		{
			return _lastTimer;
		}

		/**
		 * @private
		 */
		public function set lastTimer(value:String):void
		{
			_lastTimer = value;
		}
		
		public function copyLifeAndActBeforereleaseMyself():void
		{
			GD_AllFriends.instance.saveHiredFriendPartInfo(this._playerID,this.character.life,this.actPoint);
		}
	
		public function releaseHiredFriendGdCharate():void
		{
			this.isUpdateTime=false;
			this.character.gd_characterPlay=null;
			this.character.release();
			this.character=null;
		}

		/**
		 * 雇佣好友所在的平台 
		 */
		public function get pf():String
		{
			return _pf;
		}

		/**
		 * @private
		 */
		public function set pf(value:String):void
		{
			_pf = value;
		}


	}
}